#include <stdio.h>
#include <unistd.h>   // sleep()
#include <stdlib.h>   // exit()

int main()
{
    pid_t id = fork();
    if(id < 0){    //创建进程失败fork返回 -1
        perror("fork");    
        return 1;
    }
    else if(id > 0){  //父进程
        while(1){
            printf("i am parent , pid = %d, ppid = %d\n", getpid(), getppid());
            sleep(1);
        }
    }
    else if(id == 0){ //子进程
        int count = 5;
        while(count--){
            printf("i am child , pid = %d, ppid = %d\n", getpid(), getppid());
            sleep(2);
        }   //执行10s后子进程退出
            exit(0);
    }
    
    return 0;
}
